<?php
/**
 * DBShop 电子商务系统
 *
 * ==========================================================================
 * @link      https://www.dbshop.net/
 * @copyright 北京珑大钜商科技有限公司，并保留所有权利。
 * @license   https://www.dbshop.net/license.html License
 * ==========================================================================
 *
 * @author    静静的风 <baron@loongdom.cn>
 *
 */

namespace Goods\Service;

use Doctrine\ORM\EntityManager;
use Goods\Entity\GoodsOtherTag;

class GoodsOtherTagManager
{
    private $entityManager;

    public function __construct(
        EntityManager $entityManager
    )
    {
        $this->entityManager = $entityManager;
    }

    /**
     * 添加聚合标签
     * @param array $data
     * @return GoodsOtherTag
     * @throws \Doctrine\ORM\Exception\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function addOtherTag(array $data)
    {
        $otherTag = new GoodsOtherTag();
        $otherTag->valuesSet($data);

        $this->entityManager->persist($otherTag);
        $this->entityManager->flush();

        return $otherTag;
    }

    /**
     * 编辑聚合便签
     * @param array $data
     * @param GoodsOtherTag $goodsOtherTag
     * @return GoodsOtherTag
     * @throws \Doctrine\ORM\Exception\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function editOtherTag(array $data, GoodsOtherTag $goodsOtherTag)
    {
        $goodsOtherTag->valuesSet($data);
        $this->entityManager->flush();

        return $goodsOtherTag;
    }

    /**
     * 删除聚合标签
     * @param GoodsOtherTag $goodsOtherTag
     * @return void
     * @throws \Doctrine\ORM\Exception\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function deleteOtherTag(GoodsOtherTag $goodsOtherTag)
    {
        $this->entityManager->remove($goodsOtherTag);
        $this->entityManager->flush();
    }
}